﻿using System.ComponentModel.DataAnnotations;

namespace API.Attribute
{
    public class RequiredFieldAttribute : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null || (value is string str && string.IsNullOrWhiteSpace(str)))
            {
                return new ValidationResult($"{validationContext.DisplayName} 是必填字段");
            }
            return ValidationResult.Success;
        }
    }
}
